package common.Tables;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * CandidateArrives include Client, Candidate ,Job and notes about the candidate that arrive.
 * this CandidateArrives have many arrangements.   
 * @author Orit
 *
 */
public class CandidateArrives implements Table, Serializable{

	private static final long serialVersionUID = 1L;
	private long id;			 //serial number of the CandidateArrives
	private Client clientId;	 //the client
	private Candidate candidateId;	//the candidate
	private Job jobId;				//the job
	private String date;			//arriving date of this candidate
	private String notes;			//notes about him
	private Set<Arrangement> arrangements = new HashSet<Arrangement>(0);
	private String printCandidateArrive="";
	
	
	//////////////----------C'tor- all options------/////////////////////
	/**
	 * C'tor  include set all members
	 */
	public CandidateArrives(Client client,Candidate can,Job job, String arriveDate,String notes) {
		this.clientId = client;
		this.candidateId =can;
		this.jobId = job;
		this.date = arriveDate;
		this.notes = notes;
	}	
	/**
	 * Default C'tor
	 */
	public CandidateArrives() {
	}
	//////////////----------Getters && Setters ------/////////////////////
	/**
	 * set the client Object of the candidate that arrive 
	 */
	public void setClientId(Client clientId) {
		this.clientId = clientId;
	}
	/**
	 * @return client Object of the candidate that arrive
	 */
	public Client getClientId() {
		return clientId;
	}	
	/**
	 * set the Candidate Object of the candidate that arrive 
	 */
	public void setCandidateId(Candidate candidateId) {
		this.candidateId = candidateId;
	}
	/**
	 * @return Candidate Object of the candidate that arrive
	 */
	public Candidate getCandidateId() {
		return candidateId;
	}
	/**
	 * @return Job Object of the candidate that arrive
	 */	
	public void setJobId(Job jobId) {
		this.jobId = jobId;
	}
	/**
	 * @return job Object of the candidate that arrive
	 */
	public Job getJobId() {
		return jobId;
	}
	/**
	 * set serial number of the CandidateArrives
	 */
	public void setId(long id) {
		this.id = id;
	}
	/**
	 * @return serial number of the CandidateArrives
	 */
	public long getId() {
		return id;
	}
	/**
	 * set arriving date of the candidate
	 * @param date - arriving date
	 */
	public void setDate(String date) {
		this.date = date;
	}
	/**
	 * @return - arriving date  of the candidate
	 */
	public String getDate() {
		return date;
	}
	/**
	 * set notes about the candidate that arrive
	 */
	public void setNotes(String notes) {
		this.notes = notes;
	}
	/**
	 * @return notes about the candidate that arrive
	 */
	public String getNotes() {
		return notes;
	}
	/**
	 * set arrangements set 
	 * @param arrangements - all arranges of this candidate that arrive
	 */
	public void setArrangements(Set<Arrangement> arrangements) {
		this.arrangements = arrangements;
	}
	/**
	 * @return all arranges of this candidate that arrive
	 */
	public Set<Arrangement> getArrangements() {
		return arrangements;
	}
	
	/**
	 * this method handle the format of print Candidate Arrive
	 * attention: this method should be called only from server! (because of lazy initializer)
	 */
	public void setPrintCandidateArrive() {
		printCandidateArrive =  candidateId.getCandidateName().trim()  +", "+
				clientId.getClientName().trim()+", "+jobId.getJob().trim()  +" ("+ id + ")";
	}
	/**
	 * @return the print format
	 */
	public String getPrintCandidateArrive() {
		return printCandidateArrive;
	}
	/**
	 * @param other
	 * @return
	 * attention: this method should be called only from server! (because of lazy initializer)
	 */
	public boolean isEqualByNames(CandidateArrives other){
		if (jobId.getJob().trim().equals(other.getJobId().getJob().trim())&& 
			clientId.getClientName().trim().equals(other.getClientId().getClientName().trim()) &&
			candidateId.getCandidateName().trim().equals(other.getCandidateId().getCandidateName().trim()) &&
			date.trim().equals(other.getDate().trim())){
			return true;
		}
		return false;
	}
	
	@Override
	public boolean equals(Object other) {
		// TODO Auto-generated method stub
		CandidateArrives ca = (CandidateArrives) other;
		if (ca.getId()==id){
			return true;
		}
		return false;
	}
}
